package com.njth.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import org.apache.commons.logging.*;

public class DBManager {
	protected static final Log log = LogFactory.getLog(new DBManager()
			.getClass());

	public static Connection getConnection(Map<String, String> dbInfo) {

		Connection conn = null;

		try {
			Class.forName(dbInfo.get("DBDriver")).newInstance();
			conn = DriverManager.getConnection(dbInfo.get("DBURL"), dbInfo
					.get("DBUser"), dbInfo.get("DBPass"));
		} catch (InstantiationException e) {
			log.info("-------------------------" + e.getMessage());
		} catch (IllegalAccessException e) {
			log.info("-------------------------" + e.getMessage());
		} catch (ClassNotFoundException e) {
			log.info("-------------------------" + e.getMessage());
		} catch (SQLException e) {
			log.info("-------------------------" + e.getMessage());
		}
 
		return conn;

	}

	public static void closeConnection(Connection conn) {

		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}

}
